#include "Skydome.h"
#include "LightingManager.h"
#include "ScreenManager.h"
#include "DX11ShaderManager.h"
#include "DX11TextureManager.h"
#include "Timer.h"

Skydome::Skydome()
{
	m_cloudTranslation = D3DXVECTOR2(0.0f, 0.0f);
	m_skyColour = D3DXVECTOR4(0.0f, 0.0f, 0.0f, 1.0f);
	m_colourAdd = 0;
}

Skydome::~Skydome()
{
	if (m_pMesh)
	{
		delete m_pMesh;
	}
}

void Skydome::Draw()
{

	TheScreenManager::Instance()->SetFrontBackDrawStencilState();

	// turn depth buffer on and off
	// can add this stuff to screen manager later
	m_pMesh->Scale(200.0f, 200.0f, 200.0f);
	m_pMesh->Draw();

	TheScreenManager::Instance()->EnableBlending();

	m_pCloudsMesh->SetTextureTranslation(m_cloudTranslation);

	m_pCloudsMesh->Rotate(TheTimer::Instance()->GetTime() * 0.1f, 0.0f, 1.0f, 0.0f);
	m_pCloudsMesh->Scale(199.0f, 199.0f, 199.0f);
	m_pCloudsMesh->Draw();
	TheScreenManager::Instance()->DisableBlending();

	TheScreenManager::Instance()->SetDefaultStencilState();
/*
	TheScreenManager::Instance()->GetDeviceContext()->RSSetState(m_pCullingRasteriserState);
	TheScreenManager::Instance()->GetDeviceContext()->OMSetDepthStencilState(
		TheScreenManager::Instance()->GetDepthStateState(), 1);*/
}

void Skydome::Update()
{
}

void Skydome::Initialise()
{	
	m_pMesh = new ObjMesh();
	m_pCloudsMesh = new ObjMesh();
	m_pMesh->Load("skydome", "../../Assets/Skydome2.obj", L"Skydome.hlsl");
	m_pCloudsMesh->Load("clouds", "../../Assets/Skydome2.obj", L"Clouds.hlsl");
	m_skyColour.x = 0.3f;
	m_skyColour.y = 0.3f;
	m_skyColour.z = 0.8f;
	m_pMesh->SetColour(m_skyColour);
	
	std::wstring meshTexture = L"../../Assets/Skydome3.png";
	TheDX11TextureManager::Instance()->LoadTexture(meshTexture);
	m_pMesh->ChangeTexture(TheDX11TextureManager::Instance()->UseTexture(meshTexture));
	TheDX11TextureManager::Instance()->LoadTexture(meshTexture);
	m_pCloudsMesh->ChangeTexture(TheDX11TextureManager::Instance()->UseTexture(meshTexture));

}